<?php
// +----------------------------------------------------------------------
// | Options服务服务层
// +----------------------------------------------------------------------
// | 主要服务于Options数据处理
// +----------------------------------------------------------------------
// | 错误编码头 214xxx
// +----------------------------------------------------------------------
namespace common\service;

use common\model\OptionsModel;
use common\model\TenantOptionsModel;
use common\model\TenantStepCategoryLevelModel;
use support\ErrorCode;

class TenantOptionsService
{

    /**
     * 保存租户配置
     * @param $data
     * @return array|bool|int|string
     * @throws \Exception
     */
    public function save($data)
    {
        $tenantId = $data['tenant_id'];
        $tenantOptions = model(TenantOptionsModel::class)->where(['tenant_id' => $tenantId])->find();
        if (empty($tenantOptions)) {
            return model(TenantOptionsModel::class)->addItem($data);
        } else {
            $data['id'] = $tenantOptions['id'];
            return model(TenantOptionsModel::class)->modifyItem($data);
        }
    }
}
